﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Globalization;
using MockPrjTeam4.Entity;
using MockPrjTeam4.Common;

namespace MockPrjTeam4.DAO
{
    public class BestContactMethodDAO
    {
        public static BestContactMethod GetBestContactMethodObject(IDataRecord read)
        {
            if (read == null)
                return null;
            return new BestContactMethod
            {
                BestContactMethodId = Methods.ConvertNumber(read[BestContactMethod.FieldBestContactMethodId].ToString()),
                BestContactMethodName = Methods.ConvertString(read[BestContactMethod.FieldBestContactMethodName].ToString())
            };
        }


        public static IList<BestContactMethod> ListBestContactMethod()
        {
            var query = string.Format(CultureInfo.CurrentCulture,
                "SELECT * FROM BestContactMethod");
            List<BestContactMethod> bcm = new List<BestContactMethod>();
            using(var read = SqlHelper.ExecuteReader(query))
            {
                try
                {
                    while (read.Read())
                    {
                        bcm.Add(GetBestContactMethodObject(read));
                    }
                    return bcm;
                }
                catch (System.Exception ex)
                {
                    return null;
                }
            }
        }
    }
}